import Vue from 'vue'
import Router from 'vue-router'
// 导入推荐学习的组件
import Recommend from '@/components/Recommend'
import Users from '@/components/Users'
import Upload from '@/components/Upload'
import DownLoad from '@/components/DownLoad'
import register from '@/views/login/register'
Vue.use(Router)
/* Layout */

export const constantRoutes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    name: 'register',
    component: register,
    hidden: true,
    meta: {
      showNav: true
    }
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: () => import('@/layout'),
    redirect: '/home',
    meta: { title: '首页', icon: 'icon' },
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/home')
        // meta: { title: '首页', }
      },
      {
        path: 'recommend.',
        name: 'recommend',
        component: () => import('@/components/Recommend'),
        meta: { title: '推荐学习' }
      },
      {
        path: 'interflow',
        name: 'interflow',
        component: () => import('@/components/Interflow'),
        meta: { title: '用户交流区' },
        // children: [
        //   {
        //     path: 'reply',
        //     name: 'reply',
        //     components: () => import('@/components/Reply')
        //   }
        // ]
      },
      {
        path: 'upload',
        name: 'upload',
        component: () => import('@/components/Upload'),
        meta: { title: '资源上传' }
      },
      {
        path: 'downLoad',
        name: 'downLoad',
        component: () => import('@/components/DownLoad'),
        meta: { title: '资源浏览与下载' }
      }
    ]
  },
  {
    path: '/user',
    name: 'user',
    component: () => import('@/layout'),
    redirect: '/user',
    meta: { title: '用户管理', icon: 'icon' },
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/components/Users')
        // meta: { title: '用户管理', }
      },
      {
        path: 'user',
        name: 'user',
        component: () => import('@/components/Users'),
        meta: { title: '用户列表' }
      },
      {
        path: 'profile',
        name: 'profile',
        component: () => import('@/components/Profile'),
        meta: { title: '个人中心' }
      },
      {
        path: 'help',
        name: 'help',
        component: () => import('@/components/Help'),
        meta: { title: '帮助' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})


const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
